home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 007a / cug315.zip / HPGLPLOT.C < prev    next >
Text File  |  1990-05-16  |  3KB  |  145 lines

  1. /* Modified 11/89 by T Clune to support y min/max arguments to hpgl_bar() */
  2. /* and hpgl_line(). */
  3.  
  4. /* hpglplot.c was written 3/89 by T Clune for Eye Research Institute */
  5. /* to output hpgl files of graphed data (bar charts or line graphs) */
  6. /* Copyright (c) 1989 E.R.I.  All Rights Reserved. */
  7.  
  8.  
  9. #include "ansi.h"
  10. #include "hpglplot.h"
  11. #include <stdlib.h>
  12. #include <math.h>
  13. #include <stdio.h>
  14. #include <conio.h>
  15.  
  16. static int hp_xlow = 1000;
  17. static int hp_xhigh = 9192;
  18. static int hp_ylow = 350;
  19. static int hp_yhigh = 7400;
  20. static int axis_offset=30;
  21.  
  22.  
  23. /* hpgl_bar() creates a file of hpgl commands for drawing a bar chart */
  24. /* using data array, which has n members */
  25.  
  26. void hpgl_bar(data, n, minval, maxval)
  27. double data[];
  28. int n;
  29. double minval, maxval;
  30. {
  31.  
  32.     FILE *f;
  33.     char string[80];
  34.     int i;
  35.     double y_min, y_max;
  36.     int x,y,y_low;
  37.  
  38.  
  39.     printf("Enter filename for HPGL file\n");
  40.     gets(string);
  41.     f=fopen(string,"w");
  42.     if(f==NULL)
  43.     {
  44.     printf("Error opening output file.  Press any key to exit routine.\n");
  45.     getch();
  46.     return;
  47.     }
  48.  
  49.     y_min=minval;
  50.     y_max=maxval;
  51.  
  52.     /* initialize plotter */
  53.     hpgl_init(f);
  54.  
  55.     /* make x-axis */
  56.     x=int_scale(0,0,n,hp_xlow,hp_xhigh);
  57.     y=hp_ylow-axis_offset;
  58.  
  59.     hpgl_startline(f,x,y);
  60.  
  61.     x=int_scale(n,0,n,hp_xlow,hp_xhigh);
  62.     hpgl_line(f,x,y);
  63.  
  64.     hpgl_endline(f);
  65.  
  66.     y_low=dbl_scale(y_min,y_min,y_max,hp_ylow,hp_yhigh);
  67.  
  68.     for(i=0;i<n;i++)
  69.     {
  70.     x=int_scale(i,0,n,hp_xlow,hp_xhigh);
  71.     y=dbl_scale(data[i],y_min,y_max,hp_ylow,hp_yhigh);
  72.     hpgl_startline(f,x,y);
  73.     hpgl_line(f,x,y_low);
  74.     hpgl_endline(f);
  75.     }
  76.  
  77.  
  78.     fclose(f);
  79.  
  80.  
  81. }
  82.  
  83.  
  84.  
  85. /* hpgl_graph() draws a line graph using data array, which has n members */
  86.  
  87. void hpgl_graph(data,n,minval, maxval)
  88. double data[];
  89. int n;
  90. double minval, maxval;
  91. {
  92.  
  93.     FILE *f;
  94.     char string[80];
  95.     int i;
  96.     double y_min, y_max;
  97.     int x,y,y_low;
  98.  
  99.  
  100.     printf("Enter filename for HPGL file\n");
  101.     gets(string);
  102.     f=fopen(string,"w");
  103.     if(f==NULL)
  104.     {
  105.     printf("Error opening output file.  Press any key to exit routine.\n");
  106.     getch();
  107.     return;
  108.     }
  109.  
  110.     y_min=minval;
  111.     y_max=maxval;
  112.  
  113.     /* initialize plotter */
  114.     hpgl_init(f);
  115.  
  116.     /* make x-axis */
  117.     x=int_scale(0,0,n,hp_xlow,hp_xhigh);
  118.     y=hp_ylow-axis_offset;
  119.  
  120.     hpgl_startline(f,x,y);
  121.  
  122.     x=int_scale(n,0,n,hp_xlow,hp_xhigh);
  123.     hpgl_line(f,x,y);
  124.  
  125.     hpgl_endline(f);
  126.  
  127.     x=int_scale(0,0,n,hp_xlow,hp_xhigh);
  128.     y=dbl_scale(data[0],y_min,y_max,hp_ylow,hp_yhigh);
  129.     hpgl_startline(f,x,y);
  130.  
  131.     for(i=1;i<n;i++)
  132.     {
  133.     x=int_scale(i,0,n,hp_xlow,hp_xhigh);
  134.     y=dbl_scale(data[i],y_min,y_max,hp_ylow,hp_yhigh);
  135.     hpgl_line(f,x,y);
  136.     }
  137.  
  138.     hpgl_endline(f);
  139.  
  140.     fclose(f);
  141.  
  142.  
  143. }
  144.  
  145.